package com.codinghero.example.interview.facebook;

import java.util.Scanner;

public class SquareRoot {

	private static double TOLERANCE = 0.001;

	public static void main(String[] args) {
		double num = new Scanner(System.in).nextDouble();
		if (num >= 1)
			System.out.println(calGreaterThan1(num));
		else
			System.out.println(calLessThan1(num));
	}

	private static double calGreaterThan1(double num) {
		double lower = 1;
		double upper = num;
		return cal(num, lower, upper);
	}

	private static double calLessThan1(double num) {
		double lower = num;
		double upper = 1;
		return cal(num, lower, upper);
	}
	
	private static double cal(double num, double lower, double upper) {
		while (true) {
			double root = (lower + upper) / 2;
			if (num - root * root > TOLERANCE) {
				lower = root;
			} else if (root * root - num > TOLERANCE) {
				upper = root;
			} else {
				return root;
			}
		}
	}
}
